﻿using System.Collections.Generic;
using Gp.Scripts.Data;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Utils;

namespace Gp.Scripts.Core {
    public abstract class AtkRuleWrapper {
        protected abstract string Name { get; }

        protected virtual bool Judge(AttackActionRequest request) {
            return true;
        }

        protected abstract IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request);


        public WeakRuleWrapper<AttackActionRequest> Build() {
            return new WeakRuleWrapper<AttackActionRequest>(Name, Bonus, Judge);
        }
    }


    public class BarrierRuleWrapper : AtkRuleWrapper {
        protected override string Name => "屏障机制";

        protected override IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request)
        {
            throw new System.NotImplementedException();
        }
        // protected override bool Judge(AttackActionRequest request) {
        //     return request.Damage > 0 && request.DefencePercent < 1 && request.Target.ComBuff.HasBuff<BarrierShieldEffect>();
        // }
        //
        // protected override IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request) {
        //     request.BuffConsume.Add(request.Target.ComBuff.GetBuff<BarrierShieldEffect>());
        //     request.DefencePercent = 1;
        //     yield break;
        // }
    }


    public class DodgeRuleWrapper : AtkRuleWrapper {
        protected override string Name => "攻击闪避";

        protected override IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request)
        {
            throw new System.NotImplementedException();
        }
        // protected override bool Judge(AttackActionRequest request) {
        //     // 含有攻击闪避buff，并且技能不含无视闪避tag
        //     return request.Target.ComBuff.HasBuff<DodgeEffect>() && !request.Tags.Contains(SkillTags.IgnoreDodge);
        // }
        //
        // protected override IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request) {
        //     var buff = request.Target.ComBuff.GetBuff<DodgeEffect>();
        //     if (!MathUtil.Chance(buff.Chance)) yield break;
        //     
        //     request.IsHit = false;
        //     request.BuffConsume.Add(buff);
        // }
    }


    // public class ShieldPenetrateRuleWrapper : AtkRuleWrapper {
    //     protected override string Name => "盾牌穿透";
    //
    //     protected override bool Judge(AttackActionRequest request) {
    //         return request.Tags.Contains(SkillTags.PenetrateShield);
    //     }
    //
    //     protected override IEnumerable<KeyValuePair<object, ModifierValue>> Bonus(AttackActionRequest request) {
    //         yield break;
    //     }
    // }
}